<template>
<div class="con_box">
    <!-- 搜索栏目开始 -->
    <div class="search_column">
        <el-form ref="searchForm" :inline="true" :model="table.queryParams" label-width="95px" size="mini">
            <el-form-item label="用户名：">
                <el-input v-model="table.queryParams.keyWord"></el-input>
            </el-form-item>

            <el-form-item label="">
                <el-button type="primary" size="small" icon="el-icon-search" @click="searchSubmit">查 询</el-button>
                <el-button type="primary" size="small" icon="el-icon-refresh" @click="resetSubmit(table.queryParams)">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
    <!-- 搜索栏目结束 -->
    <!-- 操作栏开始 -->
    <!-- <div class="btns_column clearfix">
        <div class="fl">
            <el-button type="primary" size="mini" icon="el-icon-plus" @click="toAddDictionary">添加用户</el-button>
        </div>
        <div class="fr"> -->
           <!--  <a v-has="'student:import'" href="javascript:void(0)" @click="downloadTemplate" class="link_txt">
                下载导入模板
            </a> -->
        <!-- </div>
    </div> -->
    <!-- 操作栏结束 -->
	<vue-table
	    :api-url="table.apiUrl"
	    :fields="table.fields"
	    :appendParams="table.queryParams"
	    :content="self"
	    ref="dictionaryTable">
	</vue-table>
    <!-- <user-add ref="dictionaryAdd"></user-add> -->
    <user-detail ref="userDetail"></user-detail>
    <winning-information ref="winningInformation"></winning-information>
</div>
</template>
<script>
    import user_add from "./user_add"
    import user_detail from "./user_detail"
    import winning_information from "./winning_information"
    import moment from 'moment'
	export default {
		components:{
          "user-add":user_add,
          "user-detail":user_detail,
          "winning-information":winning_information,
        },
		data() {
			return {
                self:this,
				table: {
                    apiUrl: api.userManagement.userList,
                    queryParams: {
                        type:''
                    },
                    fields: [{
                            prop: "__index",
                            width: "60",
                            label: "序号",
                        },
                        {
                            prop: "login",
                            width: "150",
                            label: "用户名",
                        },
                        {
                            prop: "lastName",
                            label: "姓名",
                        },
                        {
                            prop: "userProfile.nickname",
                            label: "昵称",
                        },
                        {
                            prop: "userProfile.birthday",
                            label: "生日",
                            formatter : function(row, column, cellValue){                                
                                if(cellValue){
                                    if(cellValue){
                                        return moment(cellValue).format('YYYY-MM-DD')
                                    }
                                }
                            }
                        },
                        {
                            prop: "userProfile.sex",
                            label: "性别",
                            formatter : function(row, column, cellValue){
                                if(cellValue){
                                    return cellValue.dictValue
                                }
                            }
                        },
                        // {
                        //     prop: "userProfile.slogan",
                        //     label: "个性签名",
                        // },
                        // {
                        //     prop: "userProfile.address",
                        //     label: "地址",
                        // },
                        // {
                        //     prop: "userProfile.isSuperuser",
                        //     label: "是否是管理员",
                        // },
                        // {
                        //     prop: "userProfile.avatarUrl",
                        //     label: "封面图片",
                        // },
                        {
                            prop: "userProfile.signDays",
                            label: "连续签到天数",
                            formatter : function(row, column, cellValue){
                                if(cellValue){
                                    return cellValue + " 天"

                                }
                            }
                        },
                        {
                            prop: "userProfile.lotteryCount",
                            label: "抽奖次数",
                            formatter : function(row, column, cellValue){
                                if(cellValue){
                                    return cellValue + " 次"
                                }
                            }
                        },
                        // {
                        //     prop: "userProfile.drawName",
                        //     label: "预留中奖姓名",
                        // },
                        // {
                        //     prop: "userProfile.drawBirthday",
                        //     label: "预留中奖生日",
                        //     formatter : function(row, column, cellValue){
                        //         if(cellValue){
                        //             if(cellValue){
                        //                 return moment(cellValue).format('YYYY-MM-DD')
                        //             }
                        //         }
                        //     }
                        // },
                        // {
                        //     prop: "userProfile.drawPhone",
                        //     label: "预留中奖手机号",
                        // },
                        {
                            prop: "__action",
                            label: "操作",
                            width:200,
                            actions: [

                                {
                                    label: "重置密码",
                                    type: "edit",
                                    func: function(vm, row) {
                                       vm.resetPassword(row.id);
                                    }
                                },
                                {
                                    label: "详情",
                                    type: "edit",
                                    func: function(vm, row) {                                        
                                        vm.$refs.userDetail.showDialog(row);
                                    }
                                },
                                {
                                    label: "中奖纪录",
                                    type: "edit",
                                    func: function(vm, row) {
                                        vm.$refs.winningInformation.showDialog(row);
                                    }
                                },
                                /*{
                                    label: "删除",
                                    type: "delete",
                                    func: function(vm, row) {
                                        vm.deleteDictionary(row.id);
                                    }
                                }*/
                            ]
                        }

                    ],
                },
			}
		},
		methods: {
            // 查询
            searchSubmit(){
                this.$refs.dictionaryTable.$emit('vuetable:refresh');
            },
            //重置
            resetSubmit(val){
                for(var key in val){
                    val[key] = '';
                }
                this.$refs.dictionaryTable.$emit('vuetable:refresh');
            },
            // 中奖记录详情
            toWinningInformationDetail(){
                this.$refs.winningInformation.showDialog();
            },
            // 添加字典
            toAddDictionary(){
                this.$refs.dictionaryAdd.showDialog();
            },
            // 用户详情
            toUserDetail(){
                this.$refs.userDetail.showDialog();
            },
            // 删除用户
            deleteDictionary(id){
                let vm = this;
                vm.$confirm('是否删除该条记录！', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                })
                .then(() => {
                    // vm.axios.delete(api.userManagement.dictHandle+'/'+id)
                    // .then((response) => {
                    //     if(response.data.success){
                    //         vm.$message.success(response.data.message);
                    //         vm.$refs.dictionaryTable.$emit('vuetable:current-refresh');
                    //     }else{
                    //         vm.$message.error(response.data.message);
                    //     }
                    // });
                },()=>{})
            },
            // 重置密码
            resetPassword(id){
                let vm = this;
                vm.$confirm('是否重置此用户密码为用户名！', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                })
                .then(() => {
                    // vm.axios.delete(api.userManagement.resetPasswordList.replace(/\{id\}/, id))
                    // .then((response) => {
                    //     if(response.data.success){
                    //         vm.$message.success(response.data.message);
                    //         vm.$refs.dictionaryTable.$emit('vuetable:current-refresh');
                    //     }else{
                    //         vm.$message.error(response.data.message);
                    //     }
                    // });
                },()=>{})
            },
        },
		mounted() {
        }
	}
</script>